﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using DotConferenceSql;
using NUnit.Framework.SyntaxHelpers;

namespace TestDotConferenceSql
{
    class TestOtherWhereStatement : QueryElementBase
    {
        public override string  BuildTextQuery()
        {
            return "field1 = 1";
        }
    }

    [TestFixture]
    public class TestWhereClauseQueryElement
    {
        SqlQuery query;
        WhereClauseQueryElement whereElement;

        [SetUp]
        public void Init()
        {
            query = new SqlQuery();

            whereElement = new WhereClauseQueryElement();

            query.Elements.Add(whereElement);
        }

        [Test]
        public void TestWhereWithOneStatement()
        {
            whereElement.Elements.Add(new CustomWhereStatement("field1 LIKE(test%)"));

            Assert.That(query.BuildTextQuery(), Text.Contains("WHERE field1 LIKE(test%)"));
        }

        [Test]
        public void TestWhereWithTwoExclusiveStatements()
        {
            whereElement.Elements.Add(new CustomWhereStatement("field1 = 1"));
            whereElement.Elements.Add(new CustomWhereStatement("field2 = 2"));

            Assert.That(query.BuildTextQuery(), Text.Contains("WHERE field1 = 1 AND field2 = 2"));
        }

        [Test]
        public void TestWhereWithTwoNonExclusiveStatements()
        {
            CustomWhereStatement statement1 = new CustomWhereStatement("field1 = 1");
            statement1.ExclusiveCheck = false;

            whereElement.Elements.Add(statement1);
            whereElement.Elements.Add(new CustomWhereStatement("field2 = 2"));

            Assert.That(query.BuildTextQuery(), Text.Contains("WHERE field1 = 1 OR field2 = 2"));
        }

        [Test]
        public void TestWhereWithOtherTypeOfStatement()
        {
            whereElement.Elements.Add(new TestOtherWhereStatement());
            whereElement.Elements.Add(new CustomWhereStatement("field2 = 2"));

            Assert.That(query.BuildTextQuery(), Text.Contains("WHERE field1 = 1 AND field2 = 2"));
        }
    }
}
